package edu.hohai;

public class ApeWS {
	static String str = "";
	//指定接口URL
	//public static final String str = "http://10.196.83.53:9000";
	public static void  setPort(String port){
		str = port;
	}
	
	public static class SourceDirWS{
		/**
		 * 数据资源添加节点
		 * @param parentNodeId
		 * @param nodeName
		 * @param nodeCode
		 * @param showOrder
		 * @param nodeNote
		 * @return (String) result
		 */
		public static String addResourceNode(String parentNodeId,String nodeName,String nodeCode,
							String showOrder,String nodeNote,String jsonPCallback){
			String url = str+"/WebService/SourceDirWS/addResourceNode";
			String result = "";
			//检查一下输入字符格式是否规范
			boolean b1 = parentNodeId.matches("[0-9]+");
			boolean b2 = showOrder.matches("[0-9]+");
			if(b1 && b2){//进行加码,防止字符乱码
				String nodeNameTmp = java.net.URLEncoder.encode(nodeName);
				String nodeCodeTmp = java.net.URLEncoder.encode(nodeCode);
				String nodeNoteTmp = java.net.URLEncoder.encode(nodeNote);
				String param = "parentNodeId="+parentNodeId+"&nodeName="+nodeNameTmp+"&nodeCode="+nodeCodeTmp+
						"&showOrder="+showOrder+"&nodeNote="+nodeNoteTmp+"&jsonPCallback="+jsonPCallback;
				result = HttpRequestWS.sendGet(url, param);
				
			}else{
				System.out.println("#ERROR{***您输入的父节点parentNodeId或显示顺序showOrder不正确！(两者必须为数字)***}");
			}
			return result;
			
		}
		
		/**
		 * 数据资源修改节点
		 * @param nodeId
		 * @param nodeName
		 * @param nodeCode
		 * @param showOrder
		 * @param nodeNote
		 * @return (String) result
		 */
		public static String updateResourceNode(String nodeId,String nodeName,
				String nodeCode,String showOrder,String nodeNote,String jsonPCallback){
			String url = str+"/WebService/SourceDirWS/updateResourceNode";
			String result = "";
			//检查一下输入字符格式是否规范
			boolean b1 = nodeId.matches("[0-9]+");
			boolean b2 = showOrder.matches("[0-9]+");
			if(b1 && b2){
				//进行加码,防止字符乱码
				String nodeNameTmp = java.net.URLEncoder.encode(nodeName);
				String nodeCodeTmp = java.net.URLEncoder.encode(nodeCode);
				String nodeNoteTmp = java.net.URLEncoder.encode(nodeNote);
				String param = "nodeId="+nodeId+"&nodeName="+nodeNameTmp+"&nodeCode="+nodeCodeTmp+
						"&showOrder="+showOrder+"&nodeNote="+nodeNoteTmp+"&jsonPCallback="+jsonPCallback;
				result = HttpRequestWS.sendGet(url, param);
			}else{
				System.out.println("#ERROR{***您输入的节点nodeId或显示顺序showOrder不正确！(两者必须为数字)***}");
			}
			return result;
		}
		
		/**
		 * 数据资源删除节点
		 * @param nodeId
		 */
		public static String deleteResourceNode(String nodeId,String jsonPCallback){
			String url = str+"/WebService/SourceDirWS/deleteResourceNode";
			String result = "";
			//检查一下输入字符格式是否规范
			boolean b1 = nodeId.matches("[0-9]+");
			if(b1){
				String param = "nodeId="+nodeId+"&jsonPCallback="+jsonPCallback;
				result = HttpRequestWS.sendGet(url, param);
			}else{
				System.out.println("#ERROR{***您输入的节点nodeId不正确！(节点必须为数字)***}");
			}
			return result;
		}
		
		/**
		 * 数据资源的查询
		 * @param nodeId
		 */
		public static String getResourceNode(String nodeId,String jsonPCallback){
			String url = str+"/WebService/SourceDirWS/getResourceNode";
			String result = "";
			//检查一下输入字符格式是否规范
			boolean b1 = nodeId.matches("[0-9]+");
			if(b1){
				String param = "nodeId="+nodeId+"&jsonPCallback="+jsonPCallback;
				result = HttpRequestWS.sendGet(url, param);
			}else{
				System.out.println("#ERROR{***您输入的节点nodeId不正确！(节点必须为数字)***}");
			}
			return result;
		}
	}
	
	public static class ClassDirWS {
		//对象树部分
		/**
		 * 数据资源添加节点
		 * @param parentNodeId
		 * @param nodeName
		 * @param nodeCode
		 * @param showOrder
		 * @param nodeNote
		 * @return (String) result
		 */
		public static String addOjectNode(String parentNodeId,String nodeName,String nodeCode,
							String showOrder,String nodeNote,String jsonPCallback){
			String url = str+"/WebService/ClassDirWS/addObjectNode";
			String result = "";
			//检查一下输入字符格式是否规范
			boolean b1 = parentNodeId.matches("[0-9]+");
			boolean b2 = showOrder.matches("[0-9]+");
			if(b1 && b2){//进行加码,防止字符乱码
				String nodeNameTmp = java.net.URLEncoder.encode(nodeName);
				String nodeCodeTmp = java.net.URLEncoder.encode(nodeCode);
				String nodeNoteTmp = java.net.URLEncoder.encode(nodeNote);
				String param = "parentNodeId="+parentNodeId+"&nodeName="+nodeNameTmp+"&nodeCode="+nodeCodeTmp+
						"&showOrder="+showOrder+"&nodeNote="+nodeNoteTmp+"&jsonPCallback="+jsonPCallback;
				result = HttpRequestWS.sendGet(url, param);
				
			}else{
				System.out.println("#ERROR{***您输入的父节点parentNodeId或显示顺序showOrder不正确！(两者必须为数字)***}");
			}
			return result;
			
		}
		
		/**
		 * 数据资源修改节点
		 * @param nodeId
		 * @param nodeName
		 * @param nodeCode
		 * @param showOrder
		 * @param nodeNote
		 * @return (String) result
		 */
		public static String updateObjectNode(String nodeId,String nodeName,
				String nodeCode,String showOrder,String nodeNote,String jsonPCallback){
			String url = str+"/WebService/ClassDirWS/updateObjectNode";
			String result = "";
			//检查一下输入字符格式是否规范
			boolean b1 = nodeId.matches("[0-9]+");
			boolean b2 = showOrder.matches("[0-9]+");
			if(b1 && b2){
				//进行加码,防止字符乱码
				String nodeNameTmp = java.net.URLEncoder.encode(nodeName);
				String nodeCodeTmp = java.net.URLEncoder.encode(nodeCode);
				String nodeNoteTmp = java.net.URLEncoder.encode(nodeNote);
				String param = "nodeId="+nodeId+"&nodeName="+nodeNameTmp+"&nodeCode="+nodeCodeTmp+
						"&showOrder="+showOrder+"&nodeNote="+nodeNoteTmp+"&jsonPCallback="+jsonPCallback;
				result = HttpRequestWS.sendGet(url, param);
			}else{
				System.out.println("#ERROR{***您输入的节点nodeId或显示顺序showOrder不正确！(两者必须为数字)***}");
			}
			return result;
		}
		
		/**
		 * 数据资源删除节点
		 * @param nodeId
		 */
		public static String deleteObjectNode(String nodeId,String jsonPCallback){
			String url = str+"/WebService/ClassDirWS/deleteObjectNode";
			String result = "";
			//检查一下输入字符格式是否规范
			boolean b1 = nodeId.matches("[0-9]+");
			if(b1){
				String param = "nodeId="+nodeId+"&jsonPCallback="+jsonPCallback;
				result = HttpRequestWS.sendGet(url, param);
			}else{
				System.out.println("#ERROR{***您输入的节点nodeId不正确！(节点必须为数字)***}");
			}
			return result;
		}
		
		/**
		 * 数据资源的查询
		 * @param nodeId
		 */
		public static String getObjectNode(String nodeId,String jsonPCallback){
			String url = str+"/WebService/ClassDirWS/getObjectNode";
			String result = "";
			//检查一下输入字符格式是否规范
			boolean b1=true;
			//boolean b1 = nodeId.matches("[0-9]+");
			if(b1){
				String param = "nodeId="+nodeId+"&jsonPCallback="+jsonPCallback;
				result = HttpRequestWS.sendGet(url, param);
			}else{
				System.out.println("#ERROR{***您输入的节点nodeId不正确！(节点必须为数字)***}");
			}
			return result;
		}
	}
	
}
